#ifndef GRABERCLASS_H
#define GRABERCLASS_H

#include <QObject>
#include <QTimer>
#include <QImage>
#include <QList>

#include <conio.h>
#include <vector>
#include <string>
#include <stdio.h>
#include "xdisp_gdi.h"

#pragma comment(lib, "gdiplus.lib")

class GraberClass : public QObject
{
    Q_OBJECT
public:
    explicit GraberClass(QObject *parent = Q_NULLPTR);
    static int screen_size_change(int width, int height, int bitcount, void *param);
    static int frame_callback(dp_frame_t *frame);
    static GraberClass* GraberClassPointer;
private:
    bool isSendPermit();
    QTimer *m_grabTimer;
    QTimer *m_heartbeatTimer;
    int m_grabInterval;
    int m_heartbeatInterval ;
    int m_screenNumber;

    dp_create_t ct;
    void* handle ;
    bool flag_start_screenshot;
    QImage image ;

    //ping-pong
    int m_currentTileNum;
    int m_receivedTileNum;
    int m_permitCounter;

signals:
    void finished();
    void imageParameters(const QSize &imageSize);
    void originalImage(qint16 pox,qint16 poy,const QImage &image,int sendNum) ;
    void screenPositionChanged(const QPoint &pos);
    void heartBeatTimeOut();
public slots:
    void start();
    void stop();
    void setInterval(int msec){m_grabInterval = msec;}
    void changeScreenNum();
    void startSending();
    void setReceivedNum(quint16 num);
    void stopSending();
    void updateImage();

    void newSoFlash();
    void heartBeat();

};

#endif // GRABERCLASS_H
